import { getLogistics, getOrdersList } from '@/api/orders'

export default {
  namespaced: true,
  state: {
    // 订单列表
    ordersList: [],
    // 订单总数
    total: 0,
    // 送货时间线列表
    logisticsList: [],
    // 送货时间线弹框
    ordersStepsVisible: false,
    // 修改地址弹框
    ordersAddressVisible: false,
    flag: false
  },
  mutations: {
    setOrdersList (state, {
      list,
      total
    }) {
      state.ordersList = list
      state.total = total
    },
    setLogisticsList (state, {
      list
    }) {
      state.logisticsList = list
      state.ordersStepsVisible = true
    },
    setOrdersStepsVisible (state, flag) {
      state.ordersStepsVisible = flag
    },
    setOrdersAddressVisible (state) {
      state.ordersAddressVisible = !state.ordersAddressVisible
    },
    // 避免死循环
    setFlag (state, flag) {
      state.flag = flag
    }
  },
  actions: {
    async getNewOrdersList (context, payload) {
      const res = await getOrdersList(payload)
      // console.log(res)
      context.commit('setOrdersList', {
        list: res.data.goods,
        total: res.data.total
      })
    },
    async getLogisticsList (context) {
      const res = await getLogistics()
      // console.log(res.data)
      context.commit('setLogisticsList', { list: res.data })
    }
  }
}
